package fudan.se.lab2.controller;

import fudan.se.lab2.controller.request.CommentPostRequest;
import fudan.se.lab2.controller.request.OpenPostRequest;
import fudan.se.lab2.controller.request.RebuttalRequest;
import fudan.se.lab2.domain.Post;
import fudan.se.lab2.domain.Rebuttal;
import fudan.se.lab2.service.PostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class PostController {
    private final PostService postService;

    @Autowired
    public PostController(PostService postService) {
        this.postService = postService;
    }

    @PostMapping("/commentPost")
    public ResponseEntity<Post> commentPost(@RequestBody CommentPostRequest request) {
        return ResponseEntity.ok(postService.commentPost(request));
    }

    @PostMapping("/sendRebuttal")
    public ResponseEntity<Rebuttal> sendRebuttal(@RequestBody RebuttalRequest request) {
        return ResponseEntity.ok(postService.sendRebuttal(request));
    }

    @PostMapping("/myDiscussions")
    public ResponseEntity<List<Post>> allPostIJoined(@RequestBody String username) {
        return ResponseEntity.ok(postService.allPostIJoined(username));
    }

    @PostMapping("/allRebuttalIReceived")
    public ResponseEntity<List<Rebuttal>> allRebuttalIReceived(@RequestBody String username) {
        return ResponseEntity.ok(postService.allRebuttalIReceived(username));
    }

    @PostMapping("/getPost")
    public ResponseEntity<Post> getPosts(@RequestBody OpenPostRequest request) {
        return ResponseEntity.ok(postService.getPosts(request));
    }
}
